<?php

namespace App\Http\Controllers;

use App\Library\Lock;
use App\Library\Requests\Base\BasePageRequest;
use App\Library\Requests\Base\SerialNumberRequest;
use App\Library\Requests\ProductOrder\ProductOrderCheckRequest;
use App\Library\Requests\ProductOrder\ProductOrderCreateRequest;
use App\Library\Requests\ProductOrder\ProductOrderCustomerServicePageRequest;
use App\Library\Requests\ProductOrder\ProductOrderDeliveryRequest;
use App\Library\Requests\ProductOrder\ProductOrderPageRequest;
use App\Library\Requests\ProductOrder\ProductOrderPaymentRequest;
use App\Library\Requests\ProductOrder\ProductOrderSellerPageRequest;
use App\Library\Requests\ProductOrder\ProductOrderSellerRemarkRequest;
use App\Library\Requests\ProductOrder\ProductOrderUserPageRequest;
use App\Library\Service\ProductOrderService;
use Illuminate\Http\JsonResponse;
use Illuminate\Support\Facades\Log;

class ProductOrderController extends BaseController
{
    /**
     * @param ProductOrderService $service
     */
    public function __construct(ProductOrderService $service)
    {
        $this->service = $service;
    }

    /**
     * paging
     * @param ProductOrderPageRequest $request
     * @return JsonResponse
     */
    public function paging(ProductOrderPageRequest $request): JsonResponse
    {
        return $this->service->paging($request);
    }

    /**
     * userPaging
     * @param ProductOrderUserPageRequest $request
     * @return JsonResponse
     */
    public function userPaging(ProductOrderUserPageRequest $request): JsonResponse
    {
        return $this->service->userPaging($request);
    }

    /**
     * sellerPaging
     * @param ProductOrderSellerPageRequest $request
     * @return JsonResponse
     */
    public function sellerPaging(ProductOrderSellerPageRequest $request): JsonResponse
    {
        return $this->service->sellerPaging($request);
    }

    /**
     * userDetail
     * @param SerialNumberRequest $request
     * @return JsonResponse
     */
    public function userDetail(SerialNumberRequest $request): JsonResponse
    {
        return $this->service->userDetail($request);
    }

    /**
     * sellerDetail
     * @param SerialNumberRequest $request
     * @return JsonResponse
     */
    public function sellerDetail(SerialNumberRequest $request): JsonResponse
    {
        return $this->service->sellerDetail($request);
    }

    /**
     * create
     * @param ProductOrderCreateRequest $request
     * @return JsonResponse
     */
    public function create(ProductOrderCreateRequest $request): JsonResponse
    {
        return Lock::get(__CLASS__ . __FUNCTION__, function () use ($request) {
            return $this->service->create($request);
        });
    }

    /**
     * check
     * @param ProductOrderCheckRequest $request
     * @return JsonResponse
     */
    public function check(ProductOrderCheckRequest $request): JsonResponse
    {
        return $this->service->check($request);
    }

    /**
     * cancel
     * @param SerialNumberRequest $request
     * @return JsonResponse
     */
    public function cancel(SerialNumberRequest $request): JsonResponse
    {
        return Lock::get(__CLASS__ . __FUNCTION__ . $request->serialNumber, function () use ($request) {
            return $this->service->cancel($request);
        });
    }

    /**
     * payment
     * @param ProductOrderPaymentRequest $request
     * @return JsonResponse
     */
    public function payment(ProductOrderPaymentRequest $request): JsonResponse
    {
        return Lock::get(__CLASS__ . __FUNCTION__ . $request->serialNumber, function () use ($request) {
            return $this->service->payment($request);
        });
    }

    /**
     * userDelete
     * @param SerialNumberRequest $request
     * @return JsonResponse
     */
    public function userDelete(SerialNumberRequest $request): JsonResponse
    {
        return Lock::get(__CLASS__ . __FUNCTION__ . $request->serialNumber, function () use ($request) {
            return $this->service->userDelete($request);
        });
    }

    /**
     * confirm
     * @param SerialNumberRequest $request
     * @return JsonResponse
     */
    public function confirm(SerialNumberRequest $request): JsonResponse
    {
        return Lock::get(__CLASS__ . __FUNCTION__ . $request->serialNumber, function () use ($request) {
            return $this->service->confirm($request);
        });
    }

    /**
     * 统计
     * @return JsonResponse
     */
    public function tj(): JsonResponse
    {
        return $this->service->tj();
    }

    /**
     * 统计
     * @return JsonResponse
     */
    public function extTj(): JsonResponse
    {
        return $this->service->extTj();
    }

    /**
     * 发货
     * @param ProductOrderDeliveryRequest $request
     * @return JsonResponse
     *
     */
    public function delivery(ProductOrderDeliveryRequest $request): JsonResponse
    {
        return Lock::get(__CLASS__ . __FUNCTION__ . $request->serialNumber, function () use ($request) {
            return $this->service->delivery($request);
        });
    }

    /**
     * 查看物流信息
     * @param SerialNumberRequest $request
     * @return JsonResponse
     *
     */
    public function logistics(SerialNumberRequest $request): JsonResponse
    {
        return $this->service->logistics($request);
    }

    /**
     * 自提
     * @param SerialNumberRequest $request
     * @return mixed
     *
     */
    public function selfPickup(SerialNumberRequest $request): JsonResponse
    {
        return $this->service->selfPickup($request);
    }

    /**
     * 商家备注
     * @param ProductOrderSellerRemarkRequest $request
     * @return JsonResponse
     *
     */
    public function sellerRemark(ProductOrderSellerRemarkRequest $request): JsonResponse
    {
        return $this->service->sellerRemark($request);
    }

    /**
     *
     * @param ProductOrderCustomerServicePageRequest $request
     * @return JsonResponse
     *
     */
    public function customerServicePaging(ProductOrderCustomerServicePageRequest $request): JsonResponse
    {
        return $this->service->customerServicePaging($request);
    }

    /**
     * plugAnnounce
     * @param BasePageRequest $request
     * @return JsonResponse
     *
     */
    public function plugAnnounce(BasePageRequest $request): JsonResponse
    {
        return $this->service->plugAnnounce($request);
    }
}
